package loki
import (
"time"
"github.com/K-Phoen/sdk"
)
type Option func (query *Loki )
type Loki struct {
Builder sdk .AlertQuery
}
func New (ref string , query string , options ...Option ) *Loki {
nope := false
loki := &Loki {
Builder : sdk .AlertQuery {
RefID : ref ,
QueryType : "" ,
DatasourceUID : "__FILL_ME__" ,
RelativeTimeRange : &sdk .AlertRelativeTimeRange {},
Model : sdk .AlertModel {
RefID : ref ,
Expr : query ,
Format : "time_series" ,
Hide : &nope ,
Datasource : sdk .AlertDatasourceRef {
UID : "__FILL_ME__" ,
Type : "loki" ,
},
Interval : "" ,
IntervalMs : 15000 ,
},
},
}
for _ , opt := range append (defaults (), options ...) {
opt (loki )
}
return loki
}
func defaults() []Option {
return []Option {
TimeRange (10 *time .Minute , 0 ),
}
}
func TimeRange (from time .Duration , to time .Duration ) Option {
return func (loki *Loki ) {
loki .Builder .RelativeTimeRange .From = int (from .Seconds ())
loki .Builder .RelativeTimeRange .To = int (to .Seconds ())
}
}
func Legend (legend string ) Option {
return func (loki *Loki ) {
loki .Builder .Model .LegendFormat = legend
}
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .